﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace iLangl.Model
{
	public class LanguagesRequestContext : BaseContext
	{
		IList<Language> languages;
		public override void SetContext(object context)
		{
			base.SetContext(context);
			if (context is IList<Language>)
			{
				languages = context as IList<Language>;
				
			}

		}

		public override object GetContext()
		{
			if (languages == null)
				return string.Empty;
			startDocument();

			Write(writer);

			return endDocument();
		}

		public void Write(XmlWriter writer)
		{
			writer.WriteStartElement("Languages");

			InitExtendedAttributes(writer, languages);
			InitExtendedElements(writer, languages);

			foreach (Language lang in languages)
			{
				writer.WriteStartElement("Language");

				writer.WriteAttributeString("langId", lang.LanguageId);
				writer.WriteAttributeString("langName", lang.LanguageName);
				writer.WriteEndElement();
			}

			writer.WriteEndElement();
		}
	}
}
